Sketch in debug support for DG-100 module.
authorrobertl <robertl>
Sun, 2 Sep 2007 04:24:21 +0000 (04:24 +0000)
committerrobertl <robertl>
Sun, 2 Sep 2007 04:24:21 +0000 (04:24 +0000)
dg-100.c

index 955b8ff181570f7aef1ac0ec6cc806a7173ee803..29c3ecbadd9b4829579296e0770fbe5b265838f5 100644 (file)
--- a/dg-100.c
+++ b/dg-100.c
@@ -147,6 +147,23 @@ bintime2utc(int date, int time)
        return(mkgmtime(&gpstime));
 }
 
+static void 
+dg100_debug(const char *hdr, size_t sz, unsigned char *buf)
+{
+   int i;
+
+   if (global_opts.debug_level < 1) return;
+
+   fprintf(stderr, "%s", hdr);
+   
+   for (i = 0; i < sz; i++)  {
+       fprintf(stderr, "%02x ", buf[i]);
+   }
+
+   fprintf(stderr, "\n");
+}
+
+
 /* TODO: check whether negative lat/lon (West/South) are handled correctly */
 static float
 bin2deg(int val)
@@ -268,6 +285,7 @@ dg100_send(gbuint8 cmd, const void *payload, size_t count)
        be_write16(frame + framelen - 2, 0xB0B3);
 
        n = gbser_write(serial_handle, frame, framelen);
+        dg100_debug(n == 0 ? "Sent: " : "Error Sending:", framelen, frame);
        if (n == gbser_ERROR) {
                fatal("dg_100_send: write failed\n");
        }
@@ -306,8 +324,10 @@ dg100_recv_frame(struct dg100_command **cmdinfo_result, gbuint8 **payload)
 
        /* consume input until frame head sequence 0xA0A2 was received */
        frame_head = 0;
+        dg100_debug("Receiving ", 0, NULL);
        do {
                c = dg100_recv_byte();
+               dg100_debug("", 1, &c);
                frame_head <<= 8;
                frame_head |= c;
 
@@ -336,6 +356,7 @@ dg100_recv_frame(struct dg100_command **cmdinfo_result, gbuint8 **payload)
        /* read Payload Length, Command ID, and two further bytes */
        for (i = 2; i < 7; i++) {
                buf[i] = dg100_recv_byte();
+               dg100_debug("", 1, &buf[i]);
        }
 
        payload_len_field = be_read16(buf + 2);
@@ -384,6 +405,7 @@ dg100_recv_frame(struct dg100_command **cmdinfo_result, gbuint8 **payload)
         * read the rest of the frame at once using gbser_read_wait(). */
        for (i = 7; i < frame_len; i++) {
                buf[i] = dg100_recv_byte();
+               dg100_debug("", 1, &buf[i]);
        }
 
        frame_start_seq   = be_read16(buf + 0);